<template>
  <div>
    <div class="class_mid">
      <span>题库</span>
    </div>
    <div class="xxx two" v-if="type === 0" style="height:84vh">
      <div class="practice" style="height:35vh">
        <van-button  class="btn"  type="primary" @click="trans">练习题</van-button>
      </div>
      <div class="exam" style="height:20vh">
        <van-button class="btn"  type="primary" @click="$router.push('/exem')">考试题</van-button>
      </div>
    </div>
    <div v-else-if="type === 1" class="button_b" style="height:84vh;padding:0px">
      <div class="sidebar_mid two">
        <van-sidebar  class="left" v-model="activeKey">
          <van-sidebar-item class="leftitem" v-for="item in list.userscore" :key="item.id" :title="item.title">
          </van-sidebar-item>
        </van-sidebar>
        <!-- 地方题型 -->
        <van-list
          finished-text="没有更多了"
          class="right"
        >
          <van-cell class="rightitem"   v-for="(item, index) in list.from" :key="index" @click="selected(index)" :class="{active : active == index}">
            <span   slot="default" @click="toPractive(activeKey, index)">
              <img :src="'http://upenglish.ayvvv.cn/'+item.image">
              <span class="introduce">{{ item.from }} </span>
            </span>
          </van-cell>
        </van-list>
      </div>
    </div>
  </div>
</template>

<script>
import { grade } from '@/api/question.js'
import { mapState } from 'vuex'
export default {
  name: 'question',
  data () {
    return {
      type: 0,
      activeKey: 0, // 年级
      list: [],
      active: 0, // 地区
      practiveQuestion: []
    }
  },

  created () {
    if (this.user) {
      this.onPractive()
    } else {
      this.$router.push('/login')
    }
  },
  computed: {
    ...mapState(['user', 'id'])
  },
  methods: {
    // 选题
    async onPractive () {
      const data = await grade()
      // console.log(data)
      this.list = data.data
      // console.log(this.list)
    },

    // 点谁高亮
    selected (name) {
      this.active = name
    },
    trans () {
      this.$router.push('/exercise')
    },
    // 跳转到练习题
    toPractive (id1, id2) {
      if (this.activeKey === 0 && this.list.from === '') {
        this.$toast.fail('失败文案')
      }
      this.$router.push({ path: `/practive/${id1}/${id2}` })
    }
  }
}
</script>
<style scoped lang='less'>
.practice,
.exam {
  width: 100%;
  height: 50vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.soujin {
  text-indent: 2em;
}
.text_bottom {
  margin-bottom: 100px;
}
.van-sidebar-item--select{
  color:white
}
.van-sidebar-item--select::before {
  background-color: #4c98e6;
  width: 100%;
  height: 100%;
  color:white !important;
}

.sidebar_mid {
  display: flex;
  justify-content: space-around;
  height:100%;
}
.van-cell {
  width: 500px !important;
  line-height: 200px;
  padding: 0;
  position: relative;
  img {
    width: 100%;
    height:100%;
    border-radius: 20px;
    top: 0;
    left: 0;
  }
  .introduce{
    position: absolute;
    top:40%;
    left:35%;
    height: 43px;
    width: 140px;
    text-align: center;
    line-height: 43px;
    border-radius: 20px;
    background-color: white;
  }
}
.van-cell__title, .van-cell__value {
  text-align: end;
}
.button_b {
  padding-bottom: 180px;
}
// .active {
//   background: #fd7522;
//   border: 1px solid #fd7522;
//   color: #fff;
//  }
 .btn{
   width:70%;
   background:#4c98e6;
   color:white;
   border-radius:30px;
 }
 .xxx{
   background: url(../../img/wg.jpg);
   background-size:100%;
   background-repeat: no-repeat;
 }
 .left{
   margin-top: 10%;
   height:90%
 }
 .right{
   height:95%;
   margin-top: 5%;
 }
 .leftitem{
   margin-bottom: 30%;
   padding:0px;
   height:65px;
   width: 150px;
   text-align: center;
   line-height: 65px;
   border-radius: 30px;
   border:1px  solid #ccc;
 }
 .rightitem{
   margin-bottom:5%
 }

</style>
